const timestampToTime = timestamp => {
  let date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
  let Y = date.getFullYear() + "-";
  let M =
    (date.getMonth() + 1 < 10
      ? "0" + (date.getMonth() + 1)
      : date.getMonth() + 1) + "-";
  let D =
    (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
  let h = date.getHours() + ":";
  let m = date.getMinutes() + ":";
  let s = date.getSeconds();
  return Y + M + D;
}

const getWeek = timedat => {
  let week;
  let dat = timedat.getDay();
  switch (dat) {
    case 0:
      week = "周日";
      break;
    case 1:
      week = "周一";
      break;
    case 2:
      week = "周二";
      break;
    case 3:
      week = "周三";
      break;
    case 4:
      week = "周四";
      break;
    case 5:
      week = "周五";
      break;
    case 6:
      week = "周六";
      break;
    default:
      break;
  }
  return week;
}

//验证手机号码
const MobileVerification = tel => {
  let myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
  if (!myreg.test(tel)) {
    return false;
  } else {
    return true;
  }
}

const emojiFilter = str => {
  var regStr = /[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF][\u200D|\uFE0F]|[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF]|[0-9|*|#]\uFE0F\u20E3|[0-9|#]\u20E3|[\u203C-\u3299]\uFE0F\u200D|[\u203C-\u3299]\uFE0F|[\u2122-\u2B55]|\u303D|[\A9|\AE]\u3030|\uA9|\uAE|\u3030/ig;
  return str.replace(regStr, '')
}

export default {
  timestampToTime: timestampToTime,
  getWeek: getWeek,
  MobileVerification: MobileVerification,
  emojiFilter: emojiFilter
}